package cn.moningxi.service.impl;

import cn.moningxi.bean.CBalanceLog;
import cn.moningxi.bean.CustomerInfomation;
import cn.moningxi.mapper.CBalanceLogMapper;
import cn.moningxi.service.CBalanceLogService;
import cn.moningxi.util.CustomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CBalanceLogServiceImpl implements CBalanceLogService {
    @Autowired
    CBalanceLogMapper cBalanceLogMapper;

    @Override
    public List<CBalanceLog> queryBal(CustomerInfomation onlineUser) {
        return cBalanceLogMapper.queryBal(onlineUser);
    }

    @Override
    public void insertByOrder(Integer orderMoney, String customerId) {
        CBalanceLog cBalanceLog = new CBalanceLog();
        cBalanceLog.setAmount(orderMoney);
        cBalanceLog.setCustomerId(customerId);
        cBalanceLog.setSourceSn(String.valueOf(new CustomIdGenerator().nextId(CBalanceLogServiceImpl.class)));
        cBalanceLog.setCreateTime(LocalDateTime.now());
        cBalanceLog.setChangeDesc("商品下单");
        cBalanceLogMapper.insertByOrder(cBalanceLog);
    }
}
